/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFBuscaEndereco.java
 *
 * Created on 06/09/2012, 01:38:15
 */

package ecommercial;

import ecommercial.Classes.Bairros;
import ecommercial.Classes.Cidades;
import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.Estados;
import ecommercial.Classes.Funcoes;
import ecommercial.Classes.Logradouros;
import ecommercial.Classes.Paises;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author vitiazze
 */
public class jFBuscaEndereco extends javax.swing.JDialog {

    /** Creates new form jFBuscaEndereco */
    public jFBuscaEndereco() {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        titulo_FormjLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        pesquisajTextField = new javax.swing.JTextField();
        abrirjButton = new javax.swing.JButton();
        pesquisaEnderecojButton = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradeBuscaEnderecosjTable = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        cancelarjButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFBuscaEndereco.class);
        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setName("jLabel1"); // NOI18N

        titulo_FormjLabel.setFont(resourceMap.getFont("titulo_FormjLabel.font")); // NOI18N
        titulo_FormjLabel.setForeground(resourceMap.getColor("titulo_FormjLabel.foreground")); // NOI18N
        titulo_FormjLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titulo_FormjLabel.setText(resourceMap.getString("titulo_FormjLabel.text")); // NOI18N
        titulo_FormjLabel.setName("titulo_FormjLabel"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(189, 189, 189)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(titulo_FormjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(96, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(titulo_FormjLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel3.border.titleColor"))); // NOI18N
        jPanel3.setForeground(resourceMap.getColor("jPanel3.foreground")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        pesquisajTextField.setName("pesquisajTextField"); // NOI18N

        abrirjButton.setIcon(resourceMap.getIcon("abrirjButton.icon")); // NOI18N
        abrirjButton.setContentAreaFilled(false);
        abrirjButton.setName("abrirjButton"); // NOI18N
        abrirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abrirjButtonActionPerformed(evt);
            }
        });

        pesquisaEnderecojButton.setIcon(resourceMap.getIcon("pesquisaEnderecojButton.icon")); // NOI18N
        pesquisaEnderecojButton.setText(resourceMap.getString("pesquisaEnderecojButton.text")); // NOI18N
        pesquisaEnderecojButton.setContentAreaFilled(false);
        pesquisaEnderecojButton.setName("pesquisaEnderecojButton"); // NOI18N
        pesquisaEnderecojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesquisaEnderecojButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pesquisajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(abrirjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pesquisaEnderecojButton, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(58, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pesquisaEnderecojButton)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(pesquisajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(abrirjButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setName("jPanel5"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradeBuscaEnderecosjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "#Id", "Titulo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradeBuscaEnderecosjTable.setName("gradeBuscaEnderecosjTable"); // NOI18N
        gradeBuscaEnderecosjTable.getTableHeader().setReorderingAllowed(false);
        gradeBuscaEnderecosjTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradeBuscaEnderecosjTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradeBuscaEnderecosjTable);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(0).setResizable(false);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(0).setPreferredWidth(10);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradeBuscaEnderecosjTable.columnModel.title0")); // NOI18N
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(1).setResizable(false);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(1).setPreferredWidth(325);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradeBuscaEnderecosjTable.columnModel.title1")); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        cancelarjButton.setBackground(resourceMap.getColor("cancelarjButton.background")); // NOI18N
        cancelarjButton.setIcon(resourceMap.getIcon("cancelarjButton.icon")); // NOI18N
        cancelarjButton.setText(resourceMap.getString("cancelarjButton.text")); // NOI18N
        cancelarjButton.setFocusable(false);
        cancelarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancelarjButton.setName("cancelarjButton"); // NOI18N
        cancelarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cancelarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cancelarjButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    ClassConecta conexao;
    /**
     *
     */
    int operacao;
    /**
     *
     */
    String Titulo_Form = null;

    int cod_operacao;

    public  String pais_Busca_end;
    public String estado_busca_end;
    public String cidade_busca_end;
    public String bairro_busca_end;
    public String logradouro_busca_end;


// Deste form para pessoas endereço

    public  int cod_operacao_Pais;
    public int cod_operacao_estado;
    public int cod_operacao_cidade;
    public int cod_operacao_bairro;
    public int cod_cidade_estado;
    public int cod_cidade_bairro;
    public int cod_logradouro_bairro;




//*******************************************************************************
// de pessoas endereço para este form
    public int cod_pais_estado;



    public void getGrandeBuscaEnderecos() throws ParseException, SQLException{
       //Consultar Endereços
        Paises oPais = new Paises();
        Estados oEstado = new Estados();
        Cidades oCidade = new Cidades();
        Bairros oBairro = new Bairros();
        Logradouros oLogradouro = new Logradouros();

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Id#", Titulo_Form};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradeBuscaEnderecosjTable.setModel(modeloTabela);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(0).setPreferredWidth(10);
        gradeBuscaEnderecosjTable.getColumnModel().getColumn(1).setPreferredWidth(325);


        switch (operacao) {
                case 0:
                    //Paises
try {
//            oPais.setCod_pais(codPessoaTelefone);

            resultSet = oPais.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Paises.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_PAIS")),
                    resultSet.getString("PAIS"),
                });

                pais_Busca_end = resultSet.getString("PAIS");

            }

        } catch (SQLException ex) {
            Logger.getLogger(Paises.class.getName()).log(Level.SEVERE, null, ex);
        }

                    break;  // FIM CASE 0

            case 1:
                //Estados
try {

            oEstado.setCod_pais(cod_pais_estado);

            resultSet = oEstado.getConsultarEstados();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Estados.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_ESTADO")),
                    resultSet.getString("ESTADO"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Cidades.class.getName()).log(Level.SEVERE, null, ex);
        }

                    break;  // FIM CASE 1


                    case 2:
                //Estados
try {

            oCidade.setCod_estado(cod_cidade_estado);

            resultSet = oCidade.getConsultarCidade();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Cidades.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_CIDADE")),
                    resultSet.getString("CIDADE"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Cidades.class.getName()).log(Level.SEVERE, null, ex);
        }

                    break;  // FIM CASE 2

                    case 3:
                    //Bairros
try {
            oBairro.setCod_Cidade(cod_cidade_bairro);

            resultSet = oBairro.getConsultarBairros();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Bairros.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_BAIRRO")),
                    resultSet.getString("BAIRRO"),
                });

                pais_Busca_end = resultSet.getString("BAIRRO");

            }

        } catch (SQLException ex) {
            Logger.getLogger(Bairros.class.getName()).log(Level.SEVERE, null, ex);
        }

                    break;  // FIM CASE 3

                    case 4:
                //Logradouros
try {

            oLogradouro.setCod_bairro(cod_logradouro_bairro);

            resultSet = oLogradouro.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Logradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_LOGRADOURO")),
                    resultSet.getString("LOGRADOURO"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Cidades.class.getName()).log(Level.SEVERE, null, ex);
        }

                    break;  // FIM CASE 1

        }

           
    
    
    
    }//FIM GRADE


        public void getFieldBuscaEndereco(int cod_operacao) throws ParseException{

            ResultSet rs = null;

            switch (operacao) {
                case 0:


        Paises oPais = new Paises();

        
        oPais.setCod_pais(cod_operacao);

        try {
            rs = oPais.getConsultar();
            rs.next();

            //Pegar campos
            pesquisajTextField.setText(rs.getString("PAIS"));



        } catch (SQLException ex) {
            Logger.getLogger(Paises.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;

                case 1:

                    Estados oEstado = new Estados();

        oEstado.setCod_estado(cod_operacao);

        try {
            rs = oEstado.getConsultar();
            rs.next();

            //Pegar campos
            pesquisajTextField.setText(rs.getString("ESTADO"));



        } catch (SQLException ex) {
            Logger.getLogger(Paises.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;

        case 2:

                    Cidades oCidade = new Cidades();

        oCidade.setCod_cidade(cod_operacao);

        try {
            rs = oCidade.getConsultarCidade();
            rs.next();

            //Pegar campos
            pesquisajTextField.setText(rs.getString("CIDADE"));



        } catch (SQLException ex) {
            Logger.getLogger(Paises.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;

        case 3:


        Bairros oBairro = new Bairros();


        oBairro.setCod_Bairro(cod_operacao);

        try {
            rs = oBairro.getConsultar();
            rs.next();

            //Pegar campos
            pesquisajTextField.setText(rs.getString("BAIRRO"));



        } catch (SQLException ex) {
            Logger.getLogger(Bairros.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;

        case 4:


        Logradouros oLogradouro = new Logradouros();


        oLogradouro.setCod_logradouro(cod_operacao);

        try {
            rs = oLogradouro.getConsultar();
            rs.next();

            //Pegar campos
            pesquisajTextField.setText(rs.getString("LOGRADOURO"));



        } catch (SQLException ex) {
            Logger.getLogger(Logradouros.class.getName()).log(Level.SEVERE, null, ex);
        }
        break;


    }// FIM SWITCH

    }



    private void cancelarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButtonActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_cancelarjButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        titulo_FormjLabel.setText(Titulo_Form);

        buscarjButtonActionPerformed(null);


    }//GEN-LAST:event_formWindowOpened

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            try {
                // TODO add your handling code here:
                getGrandeBuscaEnderecos();
            } catch (SQLException ex) {
                Logger.getLogger(jFBuscaEndereco.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ParseException ex) {
            Logger.getLogger(jFBuscaEndereco.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void abrirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abrirjButtonActionPerformed
        // TODO add your handling code here:

        switch (operacao) {
                case 0:

                    if(pesquisajTextField.getText().equals("")){

                    JOptionPane.showMessageDialog(null, "Campo vazio. Por favor escolha um PAÍS", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }else{
                    pais_Busca_end = pesquisajTextField.getText();
                    cod_operacao_Pais = cod_operacao;
                    }
                    break;


            case 1:

                if(pesquisajTextField.getText().equals("")){

                    JOptionPane.showMessageDialog(null, "Campo vazio. Por favor escolha um ESTADO", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }else{
                estado_busca_end = pesquisajTextField.getText();
                cod_operacao_estado = cod_operacao;
                }

                break;

            case 2:

                if(pesquisajTextField.getText().equals("")){

                    JOptionPane.showMessageDialog(null, "Campo vazio. Por favor escolha uma CIDADE", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }else{
                cidade_busca_end = pesquisajTextField.getText();
                cod_operacao_cidade = cod_operacao;
                }

                break;

            case 3:

                if(pesquisajTextField.getText().equals("")){

                    JOptionPane.showMessageDialog(null, "Campo vazio. Por favor escolha um BAIRRO", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }else{

                bairro_busca_end = pesquisajTextField.getText();
                cod_cidade_bairro = cod_operacao;
                }
                break;

            case 4:

                if(pesquisajTextField.getText().equals("")){

                    JOptionPane.showMessageDialog(null, "Campo vazio. Por favor escolha um LOGRADOURO", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }else{

                    logradouro_busca_end = pesquisajTextField.getText();
                    cod_logradouro_bairro = cod_operacao;
                }
                break;


        }



        

        this.dispose();
    }//GEN-LAST:event_abrirjButtonActionPerformed

    private void gradeBuscaEnderecosjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradeBuscaEnderecosjTableMouseClicked
        // TODO add your handling code here:


        cod_operacao = Integer.parseInt(gradeBuscaEnderecosjTable.getValueAt(gradeBuscaEnderecosjTable.getSelectedRow(), 0).toString());
            if (cod_operacao == 0) {
                return;
            }
        try {
            getFieldBuscaEndereco(cod_operacao);
        } catch (ParseException ex) {
            Logger.getLogger(jFBuscaEndereco.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_gradeBuscaEnderecosjTableMouseClicked

    private void pesquisaEnderecojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesquisaEnderecojButtonActionPerformed
        // TODO add your handling code here:

        switch (operacao){

            case 0:

        jFPaises oFormPais = new jFPaises();

        oFormPais.setTitle("Cadastro de Países");
        oFormPais.pack();
        oFormPais.setLocationRelativeTo(null);
        oFormPais.setModal(true);
        oFormPais.setVisible(true);

        buscarjButtonActionPerformed(null);
        break;

            case 1:

        jFEstados oFormEstado = new jFEstados();

        oFormEstado.setTitle("Cadastro de Estados");
        oFormEstado.pack();
        oFormEstado.setLocationRelativeTo(null);
        oFormEstado.setModal(true);
        oFormEstado.setVisible(true);

        buscarjButtonActionPerformed(null);
        break;

            case 2:

        jFCidades oFormCidade = new jFCidades();

        oFormCidade.setTitle("Cadastro de Cidades");
        oFormCidade.pack();
        oFormCidade.setLocationRelativeTo(null);
        oFormCidade.setModal(true);
        oFormCidade.setVisible(true);

        buscarjButtonActionPerformed(null);
        break;

            case 3:

        jFBairros oFormBairro = new jFBairros();

        oFormBairro.setTitle("Cadastro de bairros");
        oFormBairro.pack();
        oFormBairro.setLocationRelativeTo(null);
        oFormBairro.setModal(true);
        oFormBairro.setVisible(true);

        buscarjButtonActionPerformed(null);
        break;

            case 4:

        jFLogradouros oFormLogradouro = new jFLogradouros();

        oFormLogradouro.setTitle("Cadastro de Logradouros");
        oFormLogradouro.setDefaultCloseOperation(jFLogradouros.DO_NOTHING_ON_CLOSE);
        oFormLogradouro.pack();
        oFormLogradouro.setModal(true);
        oFormLogradouro.setLocationRelativeTo(null);
        oFormLogradouro.setVisible(true);

        buscarjButtonActionPerformed(null);
        break;
        }
    }//GEN-LAST:event_pesquisaEnderecojButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFBuscaEndereco().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton abrirjButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JButton cancelarjButton;
    private javax.swing.JTable gradeBuscaEnderecosjTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton pesquisaEnderecojButton;
    private javax.swing.JTextField pesquisajTextField;
    private javax.swing.JLabel titulo_FormjLabel;
    // End of variables declaration//GEN-END:variables

}
